package com.lt.lumentracks.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

@Slf4j
@Component
public class RequestLoggingInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        if (handler instanceof HandlerMethod hm) {
            // 获取Controller类名
            String className = hm.getBeanType().getSimpleName();
            // 获取方法名
            String methodName = hm.getMethod().getName();
            log.info("请求接口: {}.{}", className, methodName);
        }
        return true;
    }
}